package movieGandalf.DB;

import java.io.*;
import java.sql.*;
import java.util.HashMap;
import movieGandalf.dataObjects.*;

public class DBM {
	
	public void a(int[] a){
		a[0]=5;
	}
	
	/*
	public int fileRead(HashMap dest, Encoder enc, DataReader dr, Connection conn, String filename){
		
		try {
			FileInputStream in = new FileInputStream(filename);
			
			return dr.read(dest, enc, conn, in);
		}
		catch (FileNotFoundException e) {
			e.printStackTrace();
			return 0;
		}
	}*/
	
	public int fileRead(DataReader dr, Connection conn, String filename){
		
		try {
			FileInputStream in = new FileInputStream(filename);
			
			return dr.read(conn, in);
		}
		catch (FileNotFoundException e) {
			e.printStackTrace();
			return 0;
		}
	}
	
	public static void main(String[] args){
		Connection conn = null;
		
		try{
			Class.forName("com.mysql.jdbc.Driver");
			conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/DbMysql06","root","Puaehi86");
			
			Encoder enc = new Encoder();
			
			DBM dbm = new DBM();
			conn.setAutoCommit(false);
			
			//dbm.fileRead(new CountriesReader(), conn, "e:\\MovieGandalf\\countries.list");
			//dbm.fileRead(new LanguagesReader(), conn, "e:\\MovieGandalf\\language.list");
			//dbm.fileRead(new DirectorsReader(), conn, "e:\\MovieGandalf\\directors.list");
			//dbm.fileRead(new GenresReader(), conn, "e:\\MovieGandalf\\genres.list");
			//dbm.fileRead(new MPAARatingsReader(), conn, "e:\\MovieGandalf\\mpaa-ratings-reasons.list");
			DataReader dr = new ActorsReader(Gender.FEMALE);
			dbm.fileRead(dr, conn, "e:\\MovieGandalf\\actresses.list");
			dr = new ActorsReader(Gender.MALE);
			dbm.fileRead(dr, conn, "e:\\MovieGandalf\\actors.list");
			dbm.fileRead(new MoviesReader(), conn, "e:\\MovieGandalf\\movies.list");
			dbm.fileRead(new CountriesAdder(), conn, "e:\\MovieGandalf\\countries.list");
			dbm.fileRead(new ColorAdder(), conn, "e:\\MovieGandalf\\color-info.list");
			dbm.fileRead(new LanguagesAdder(), conn, "e:\\MovieGandalf\\language.list");
			dbm.fileRead(new LengthsAdder(), conn, "e:\\MovieGandalf\\running-times.list");
			dbm.fileRead(new DirectorsAdder(), conn, "e:\\MovieGandalf\\directors.list");
			dbm.fileRead(new MPAARatingsAdder(), conn, "e:\\MovieGandalf\\mpaa-ratings-reasons.list");
			dbm.fileRead(new DescriptionsReader(), conn, "e:\\MovieGandalf\\plot.list");
			dbm.fileRead(new GenresAdder(), conn, "e:\\MovieGandalf\\genres.list");
			dbm.fileRead(new ActorsAdder(), conn, "e:\\MovieGandalf\\actresses.list");
			dbm.fileRead(new ActorsAdder(), conn, "e:\\MovieGandalf\\actors.list");	
			int i=0;
		}
		catch(Exception e){
			return;
		}
		finally{
			try{
				conn.close();
			}
			catch(Exception e){}
		}
		
		return;
	}
	
}
